﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NHibernate;
using NHibernate.Criterion;

namespace SmartProject.Entity
{
    public class Priority : EntityBase
    {
        public virtual string Description { get; set; }

        public virtual int Level { get; set; }

        public static Priority GetPriority(ISession session, int priorityId)
        {
            IList<ICriterion> expressions = new List<ICriterion>();
            expressions.Add(Restrictions.Eq("Id", priorityId));
            IList<EntityBase> entities = Find(session, expressions, null, typeof(Priority));
            if (entities != null && entities.Count == 1)
            {
                return (Priority)entities[0];
            }
            return null;
        }

        public static Priority GetPriority(ISession session, string description)
        {
            IList<ICriterion> expressions = new List<ICriterion>();
            expressions.Add(Restrictions.Eq("Description", description));
            IList<EntityBase> entities = Find(session, expressions, null, typeof(Priority));
            if (entities != null && entities.Count == 1)
            {
                return (Priority)entities[0];
            }
            return null;
        }

        /// <summary>
        /// Gets the full set of priorities.
        /// </summary>
        /// <param name="session">Session used in this request.</param>
        /// <returns>List of Priority entities.</returns>
        public static IList<Priority> GetPriorities(ISession session)
        {
            IList<EntityBase> entities = Find(session, null, null, typeof(Priority));
            return (from p in entities select p as Priority).ToList();
        }
    }
}
